<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  <script>
    // 可以通过原型对象,进行扩展自定义的方法
    // 只能通过Array.prototype.??=function(){};来添加方法
    console.log(Array.prototype);
    Array.prototype.sum = function () {
      let sum = 0;
      for (let i = 0; i < this.length; i++) {
        sum += this[i];
      };
      return sum;
    };
    let j = [1, 2, 5].sum();
    console.log(j);
  </script>
</body>

</html>